//编写数组与结构的函数记录学生信息
#include<iostream>

const int SLEN = 30;
class student
{
public:
	char fullname[SLEN];
	char hobby[SLEN];
	int ooplevel;
};

int getinfo(student pa[], int n);
void display1(student st);
void display2(const student* ps);
void display3(const student pa[], int n);

int main()
{
	std::cout << "Enter class size: ";
	int class_size = 0;
	std::cin >> class_size;
	while (std::cin.get() != '\n')
		continue;

	student* ptr_stu = new student[class_size];
	int entered = getinfo(ptr_stu, class_size);
	std::cout << "name\thobby\tooplevel" << std::endl;
	for (int i = 0; i < entered; i++)
	{
		display1(ptr_stu[i]);
		display2(&ptr_stu[i]);
	}
	display3(ptr_stu, entered);
	delete[]ptr_stu;
	std::cout << "Done." << std::endl;

	return 0;
}

int getinfo(student pa[], int n)
{
	int count = 0;
	std::cout << "Enter the informations (name,hobby,ooplevel) of students(or blank to quit): " << std::endl;
	while (count < n)
	{
		std::cin.getline(pa[count].fullname, SLEN);
		if (!strlen(pa[count].fullname))
			break;
		std::cin.getline(pa[count].hobby, SLEN);
		std::cin >> pa[count].ooplevel;
		count++;
		std::cin.ignore();
	}
	return count;
}
void display1(student st)
{
	std::cout << st.fullname << '\t' << st.hobby << '\t' << st.ooplevel << std::endl;
}
void display2(const student* ps)
{
	std::cout << ps->fullname << '\t' << ps->hobby << '\t' << ps->ooplevel << std::endl;
}
void display3(const student pa[], int n)
{
	for (int i = 0; i < n; i++)
		std::cout << pa[i].fullname << '\t' << pa[i].hobby << '\t' << pa[i].ooplevel << std::endl;
}